<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #cs {
        border: 1px solid #999;
      }
    </style>
  </head>
  <body>
    <canvas id="cs" width="400px" height="400px">您的浏览器不支持canvas</canvas>
  </body>
  <script>
    var cs = document.getElementById("cs");
    if (cs.getContext("2d")) {
      var ctx = cs.getContext("2d");
      //cts.beginPath();绘制一个完整图形不同于绘制路径，不需要开启一个新路径
      ctx.fillStyle = "pink";  //注意：样式设置要放在绘制之前
      ctx.fillRect(100, 100, 200, 200);
      ctx.lineWidth = 5;
      ctx.strokeStyle = "aqua";
      ctx.strokeRect(10, 10, 100, 100);
      ctx.clearRect(150, 150, 100, 100);
    } else {
      console.log("您的浏览器不支持canvas");
    }
  </script>
</html>
